﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AliyunOpenSearch4Net.Base;
using Newtonsoft.Json;

namespace AliyunOpenSearch4Net.Suggest
{
    class SuggestRequest : RequestBase<SuggestResponse>
    {
        public SuggestRequest()
            : base(string.Empty)
        {
        }

        public string IndexName { get; set; }

        public string Query { get; set; }

        public string SuggestName { get; set; }

        public int Hint { get; set; }

        protected override void RegisterQueryItems(IList<KeyValuePair<string, string>> list)
        {
            list.Add("query", Query);
            list.Add("index_name", IndexName);
            list.Add("suggest_name", SuggestName);
            list.Add("hit", Hint.ToString());
        }
    }

    /// <summary>
    /// Suugest api response
    /// </summary>
    public class SuggestResponse : Response
    {
        /// <summary>
        /// Gets or sets the time taken by the search.
        /// </summary>
        /// <value>
        /// the time taken by the search.
        /// </value>
        [JsonProperty("searchtime")]
        public float SearchTime { get; set; }

        /// <summary>
        /// Gets or sets the returned suggestions.
        /// </summary>
        /// <value>
        /// The returned suggestions.
        /// </value>
        [JsonProperty("suggestions")]
        public Suggest[] Suggestions { get; set; }
    }

    /// <summary>
    /// Suggest
    /// </summary>
    public class Suggest
    {
        /// <summary>
        /// Gets or sets the suggestion.
        /// </summary>
        /// <value>
        /// The suggestion.
        /// </value>
        [JsonProperty("suggestion")]
        public string Suggestion { get; set; }
    }
}
